<?php $search = makeSearchLink($_GET); ?>

<?php
/*
 * Created on Sep 10, 2007
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

require('./Model/SpecalizedInserts.php');
$search = makeSearchLink($_GET);
if($fowardTo == 'ModifyTube.php' && isset($_GET['id'])) {
	$search .= '&id=' . $_GET['id'];
}
 if(isset($_POST['clearBox'])) {
 	$tubes = array();
 	$result = selectFromDatabase(array('id'), "FrozenTube", array('ContainerID' => $_POST['ContainerID']));
 	unset($_POST['clearBox']);
 	while($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
 		$_POST[$line['id']] = 'true';
 	}
 	$_POST['clear'] = "true"; //Sets up a clear function with every cell in a container
 }
 if($_POST['clear'] != "") {
 	unset($_POST['clear']);
	$_POST['CellTypeID'] = getEmptyCellType();
	$_POST['ModifiedByID'] =getEmptyMod();
	$_POST['FrozenByID'] = getEmptyResearcher();
	$_POST['FrozenDate'] = "";
	$_POST['Note'] = "";
	$_POST['PassageFrozen'] = "";
	$_POST['NumberFrozen'] = "";
	addTubes($_POST); //In specalizedInserts
	$redirect = True;
 } 
 if ($_POST['change'] != "") {
 	unset($_POST['change']);
	addTubes($_POST);
	$redirect = True;
 } 

 
 /*
  * Legacy Code, doesn't work very well, but I can't bring my self to delete it
  */
function addGeneral($table ,$values, $link, $search) {


	$select .= "<form action=\"$link?$search\" method=\"POST\" onsubmit=\"return validate_form(this)\">";
	$select .= "<input type=\"hidden\" name=\"table\" value=\"$table\">";
	$select .= "<input type=\"hidden\" name=\"id\" value=\"". $_POST['id'] . "\">";
	$select .= "<input type=\"hidden\" name=\"ContainerID\" value=\"". $_POST['ContainerID'] . "\">";
	foreach ($values as $key => $value) {
		//hack to keep from processing further allows me to avoid working to closely with the controller
		$select .= "$key <input type=\"text\" name=\"toAdd" . "[$key]\"> </br> \n";
		$falseText = (isChecked($v)) ?  "" : "checked=\"checked\"";
		$trueText = (isChecked($v)) ? "checked=\"checked\"" : "" ;
		if($type == "string" ) {
			$select.=	"<input type=\"text\" name=\"$i[$k]\" value=\"$v\">";
		}elseif($type == "int") {
				$select .= "<input type=\"radio\" name=\"$i[$k]\" value=\"1\" $trueText> Yes";
				$select .= "<br>";
				$select .= "<input type=\"radio\" name=\"$i[$k]\" value=\"0\"  $falseText> No";
		}
		
	}
	$select .= "<input type=\"submit\" name=\"add\" value=\"Add Item\">";
	return $select;
} 
?>
<HTML>
<HEAD>
<?php if($redirect): ?>
<meta HTTP-EQUIV="REFRESH" content="0; <?php echo "$fowardTo?$search"; ?>"> 
<?php endif; ?>
</HEAD>
<BODY>
<table>
<form action="<?php echo $loopTo . "?$search"?>" method="POST" onsubmit="return validate_form(this)">
<?php if(!$redirect): ?>

<?php 
 if($_POST['addCellType'] != "") {
 	require('./View/EditCellType.php');
 	$table="CellType";
 } 
 if($_POST['addMod'] != "") {
 	require('./View/EditModification.php');
 	$table="Modification";
 } 
 if($_POST['addResearcher'] != "") {
 	require('./View/EditResearcher.php');
 	$table="Researcher";
  }
?>
<input type='hidden' name="itemAdded" value="true">
<input type="hidden" name="table" value="<?php echo $table ?>">
<input type="hidden" name="id" value="<?php echo $_POST['id'] ?>">
<input type="hidden" name="ContainerID" value="<?php echo $_POST['ContainerID'] ?>">
<input type='hidden' name="size" value='1'>
<tr>
	<td>
		<input type="submit" name="update" value="Add Item">
	</td>
</tr>
<?php endif; ?>
</BODY>
</HTML>




